//
// Created by wujehy on 2020/5/3.
//

#include <iostream>
#include <GeeJoan/AuthModule.pb.h>
#include <Tools/CommonTool.h>
#include <GeeJoan/NetWorkPackage.pb.h>
using namespace  GeeJoan::Protocol::NetWork;


const char* HexCode = "0123456789ABCDEF";

int hexCharToInt(char c)
{
    if (c >= '0' && c <= '9') return (c - '0');
    if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
    if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
    return 0;
}

int HexString2Char(void **outData ,  const char*data , int len  )
{
    char *result ;
    int resultLen = len /2 ;
    if(len == 0 )
    {
        return -1;
    }

    result = (char*)malloc(resultLen);

    for (int i = 0; i < resultLen; ++i)
    {
        result[i] = ((hexCharToInt(data[i*2]) << 4) | hexCharToInt(data[i*2+1]));
    }

    *outData = result;

    return resultLen;
}


int  main(){
    char *testData = "08021001180120C8012A0474657374";
    char *outTest;
    int testLen= HexString2Char((void**)&outTest , testData , 30);

    std::cout <<" rest "<< testLen <<std::endl;

//    std::string hexString = "0a036162631203636466187b";
//    std::string buff = HexToString(hexString);
//
//    GeeJoan::Protocol::Auth::LoginRequest loginRequest;
//
//    if (loginRequest.ParseFromString(buff))
//    {
//        std::cout <<" ok "<<std::endl;
//        std::cout <<" ok "<< loginRequest.username() <<std::endl;
//
//    }
//
//   NetWorkPackageRespose respose;
//
//    respose.set_taskid(1);
//    respose.set_code(200);
//    respose.set_body("test");
//    respose.set_type_m(NetWorkPackageModel::IOTMod);
//    respose.set_type_sub(1);
//
//    std::string outstring ;
//    respose.SerializePartialToString(&outstring);
//
//    std::cout <<"out: "<<StringToHex(outstring)<<std::endl;

    return 0;
}